home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / games / nhak_src.zip / WIELD.C < prev    next >
C/C++ Source or Header  |  1993-03-16  |  6KB  |  231 lines

  1. /*    SCCS Id: @(#)wield.c    3.0    87/05/10
  2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3. /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5. #include    "hack.h"
  6.  
  7. /* Note: setuwep() with a null obj, and uwepgone(), are NOT the same!  Sometimes
  8.  * unwielding a weapon can kill you, and lifesaving will then put it back into
  9.  * your hand.  If lifesaving is permitted to do this, use
  10.  * setwuep((struct obj *)0); otherwise use uwepgone().
  11.  * (The second function should probably be #ifdef NAMED_ITEMS since only then
  12.  * may unwielding a weapon kill you, but...)
  13.  */
  14. void
  15. setuwep(obj)
  16. register struct obj *obj;
  17. {
  18.     setworn(obj, W_WEP);
  19.     if (!obj) unweapon = TRUE;    /* for "bare hands" message */
  20. }
  21.  
  22. void
  23. uwepgone()
  24. {
  25.     if (uwep) {
  26.         setnotworn(uwep);
  27.         unweapon = TRUE;
  28.     }
  29. }
  30.  
  31. static const char NEARDATA wield_objs[] = { '#', '-', WEAPON_SYM, TOOL_SYM, 0 };
  32.  
  33. int
  34. dowield()
  35. {
  36.     register struct obj *wep;
  37.     register int res = 0;
  38.  
  39.     multi = 0;
  40. #ifdef POLYSELF
  41.     if (cantwield(uasmon)) {
  42.         pline("Don't be ridiculous!");
  43.         return(0);
  44.     }
  45. #endif
  46.     if(!(wep = getobj(wield_objs, "wield"))) /* nothing */;
  47.     else if(uwep == wep)
  48.         You("are already wielding that!");
  49.     else if(welded(uwep))
  50.         weldmsg(uwep, TRUE);
  51.     else if(wep == &zeroobj) {
  52.         if(uwep == 0)
  53.         You("are already empty %s.", body_part(HANDED));
  54.         else  {
  55.           You("are empty %s.", body_part(HANDED));
  56.           setuwep((struct obj *) 0);
  57.           res++;
  58.         }
  59.     } else if(!uarmg &&
  60. #ifdef POLYSELF
  61.         !resists_ston(uasmon) &&
  62. #endif
  63.         (wep->otyp == CORPSE && wep->corpsenm == PM_COCKATRICE)) {
  64.         /* Prevent wielding cockatrice when not wearing gloves --KAA */
  65.         You("wield the cockatrice corpse in your bare %s.",
  66.             makeplural(body_part(HAND)));
  67.         You("turn to stone...");
  68.         killer_format = KILLED_BY;
  69.         killer="touching a cockatrice corpse";
  70.         done(STONING);
  71.     } else if(uarms && bimanual(wep))
  72.         You("cannot wield a two-handed %s and hold a shield.",
  73.          is_sword(wep) ? "sword" : "weapon");
  74.     else if(wep->owornmask & (W_ARMOR | W_RING | W_AMUL | W_TOOL))
  75.         You("cannot wield that!");
  76.     else {
  77.         res++;
  78.         if(wep->cursed && (wep->olet == WEAPON_SYM ||
  79.             wep->otyp == HEAVY_IRON_BALL || wep->otyp == PICK_AXE ||
  80.             wep->otyp == UNICORN_HORN ||
  81.             wep->otyp == TIN_OPENER)) {
  82.             pline("The %s %s to your %s!",
  83.             aobjnam(wep, "weld"),
  84.             (wep->quan == 1) ? "itself" : "themselves", /* a3 */
  85.             body_part(HAND));
  86.             wep->bknown = 1;
  87.         } else {
  88.             /* The message must be printed before setuwep (since
  89.              * you might die and be revived from changing weapons),
  90.              * and the message must be before the death message and
  91.              * Lifesaved rewielding.  Yet we want the message to say
  92.              * "weapon in hand", thus this kludge.
  93.              */
  94.             long dummy = wep->owornmask;
  95.             wep->owornmask |= W_WEP;
  96.             prinv(wep);
  97.             wep->owornmask = dummy;
  98.         }
  99.         setuwep(wep);
  100.     }
  101.     /* Note: Explicitly wielding a pick-axe will not give a "bashing"
  102.      * message.  Wielding one via 'a'pplying it will.
  103.      */
  104.     if(res && uwep)
  105.         unweapon = ((uwep->otyp >= BOW || uwep->otyp <= BOOMERANG) &&
  106.             uwep->otyp != PICK_AXE && uwep->otyp != UNICORN_HORN);
  107.     return(res);
  108. }
  109.  
  110. void
  111. corrode_weapon(){
  112.     if(!uwep || uwep->olet != WEAPON_SYM) return;    /* %% */
  113.     if(uwep->rustfree || objects[uwep->otyp].oc_material != METAL)
  114.         Your("%s not affected.", aobjnam(uwep, "are"));
  115.     else if (uwep->spe > -6) {
  116.         Your("%s!", aobjnam(uwep, "corrode"));
  117.         uwep->spe--;
  118.     } else    Your("%s quite rusted now.", aobjnam(uwep, Blind ? "feel" : "look"));
  119. }
  120.  
  121. int
  122. chwepon(otmp, amount)
  123. register struct obj *otmp;
  124. register int amount;
  125. {
  126.     register const char *color = Hallucination ? hcolor() :
  127.                      (amount < 0) ? black : blue;
  128.     register const char *xtime;
  129.  
  130.     if(!uwep || (uwep->olet != WEAPON_SYM && uwep->otyp != PICK_AXE
  131.             && uwep->otyp != UNICORN_HORN)) {
  132.         char buf[36];
  133.  
  134.         Sprintf(buf, "Your %s %s.", makeplural(body_part(HAND)),
  135.             (amount > 0) ? "twitch" : "itch");
  136.         strange_feeling(otmp, buf);
  137.         return(0);
  138.     }
  139.  
  140. #ifdef WORM
  141.     if(uwep->otyp == WORM_TOOTH && amount > 0) {
  142.         uwep->otyp = CRYSKNIFE;
  143.         Your("weapon seems sharper now.");
  144.         uwep->cursed = 0;
  145.         return(1);
  146.     }
  147.  
  148.     if(uwep->otyp == CRYSKNIFE && amount < 0) {
  149.         uwep->otyp = WORM_TOOTH;
  150.         Your("weapon seems duller now.");
  151.         return(1);
  152.     }
  153. #endif
  154. #ifdef NAMED_ITEMS
  155.     if(is_artifact(uwep) && restr_name(uwep, ONAME(uwep)) &&
  156.         amount<0) {
  157.         if (!Blind)
  158.         Your("%s faintly %s.", aobjnam(uwep, "glow"), color);
  159.         return(1);
  160.     }
  161. #endif
  162.     /* there is a (soft) upper and lower limit to uwep->spe */
  163.     if(((uwep->spe > 5 && amount > 0) || (uwep->spe < -5 && amount < 0))
  164.                                 && rn2(3)) {
  165.         if (!Blind)
  166.         Your("%s violently %s for a while and then evaporate%s.",
  167.         aobjnam(uwep,"glow"), color, uwep->quan == 1 ? "s" : "");
  168.         else
  169.         Your("%s.", aobjnam(uwep, "evaporate"));
  170.  
  171.         while(uwep)        /* let all of them disappear */
  172.                 /* note: uwep->quan = 1 is nogood if unpaid */
  173.         useup(uwep);
  174.         return(1);
  175.     }
  176.     if (!Blind) {
  177.         xtime = (amount*amount == 1) ? "moment" : "while";
  178.         Your("%s %s for a %s.",
  179.           aobjnam(uwep, "glow"), color, xtime);
  180.     }
  181.     uwep->spe += amount;
  182.     if(amount > 0) uwep->cursed = 0;
  183.     return(1);
  184. }
  185.  
  186. int
  187. welded(obj)
  188. register struct obj *obj;
  189. {
  190.     if (obj && obj == uwep && obj->cursed &&
  191.           (obj->olet == WEAPON_SYM || obj->otyp == HEAVY_IRON_BALL ||
  192.            obj->otyp == TIN_OPENER || obj->otyp == PICK_AXE ||
  193.            obj->otyp == UNICORN_HORN))
  194.     {
  195.         obj->bknown = 1;
  196.         return 1;
  197.     }
  198.     return 0;
  199. }
  200.  
  201. /* The reason for "specific" is historical; some parts of the code used
  202.  * the object name and others just used "weapon"/"sword".  This function
  203.  * replaced all of those.  Which one we use is really arbitrary.
  204.  */
  205. void
  206. weldmsg(obj, specific)
  207. register struct obj *obj;
  208. boolean specific;
  209. {
  210.     char buf[BUFSZ];
  211.  
  212.     if (specific) {
  213.         long savewornmask = obj->owornmask;
  214.         obj->owornmask &= ~W_WEP;
  215.         Strcpy(buf, Doname2(obj));
  216.         obj->owornmask = savewornmask;
  217.     } else
  218.         Sprintf(buf, "Your %s%s",
  219.             is_sword(obj) ? "sword" : "weapon",
  220.             plur((long)obj->quan));
  221.     Strcat(buf, (obj->quan==1) ? " is" : " are");
  222. #ifdef POLYSELF
  223.     Sprintf(eos(buf), " welded to your %s!",
  224.         bimanual(obj) ? makeplural(body_part(HAND)) : body_part(HAND));
  225. #else
  226.     Sprintf(eos(buf), " welded to your hand%s!",
  227.         bimanual(obj) ? "s" : "");
  228. #endif
  229.     pline(buf);
  230. }
  231.